#include <iostream>
#define LL long long
using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    LL a, b;

    cin >> a >> b;
    if (b % 2 == 0) {
      if (a * b % 4 != 0) {
        cout << "-1\n";
      } else {
        cout << a * b / 2 + 2 << "\n";
      }
    } else {
      if (a % 2 == 0) {
        cout << "-1\n";
      } else {
        cout << a * b + 1 << "\n";
      }
    }
  }
  return 0;
}